package com.octopus.kernal.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.criterion.DetachedCriteria;

public interface GenericDao<T extends Serializable, PK extends Serializable> {

	public T get(PK id);

	public T getWithLock(PK id, LockMode lock);

	public T load(PK id);

	public T loadWithLock(PK id, LockMode lock);

	public List<T> loadAll();
	
	public List<T> loadAll(final int offset, final int length);

	public void update(T entity);

	public void updateWithLock(T entity, LockMode lock);

	public void save(T entity);

	public void saveOrUpdate(T entity);

	public void saveOrUpdateAll(Collection<T> entities);

	public void delete(T entity);

	public void deleteWithLock(T entity, LockMode lock);

	public void deleteByKey(PK id);

	public void deleteByKeyWithLock(PK id, LockMode lock);

	public void deleteAll(Collection<T> entities);

	// -------------------- HSQL ----------------------------------------------

	public int bulkUpdate(String queryString);

	public int bulkUpdate(String queryString, Object[] values);

	public List<T> find(String queryString);

	public List<T> find(String queryString, Object[] values);
	
	public List<T> find(String queryString, final Object[] values, final int offset, final int length);
	
	public int count(final String queryString, final Object[] values);

	public List<T> findByNamedParam(String queryString, String[] paramNames, Object[] values);

	public List<T> findByNamedQuery(String queryName);

	public List<T> findByNamedQuery(String queryName, Object[] values);

	public List<T> findByNamedQueryAndNamedParam(String queryName, String[] paramNames, Object[] values);

	public Iterator<T> iterate(String queryString);

	public Iterator<T> iterate(String queryString, Object[] values);

	public void closeIterator(Iterator<T> it);

	// -------------------------------- Criteria ------------------------------

	public DetachedCriteria createDetachedCriteria();

	public Criteria createCriteria();
	
	public Integer getRowCount(DetachedCriteria criteria);

	public List<T> findByCriteria(DetachedCriteria criteria);

	public List<T> findByCriteria(DetachedCriteria criteria, int firstResult, int maxResults);
	
	public Integer countEqualByEntity(T entity);

	public List<T> findEqualByEntity(T entity, String[] propertyNames);
	
	public List<T> findEqualByEntity(T entity, String[] propertyNames, int firstResult, int maxResults);
	
	public Integer countLikeByEntity(T entity);

	public List<T> findLikeByEntity(T entity, String[] propertyNames);
	
	public List<T> findLikeByEntity(T entity, String[] propertyNames, int firstResult, int maxResults);

	public Object getStatValue(DetachedCriteria criteria, String propertyName, String StatName);

	// -------------------------------- Others --------------------------------

	public void lock(T entity, LockMode lockMode);

	public void initialize(Object proxy);

	public void flush();

}